<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>a标签动画</title>
    </head>
    <body>
        <style>
            a {
                text-decoration: none;
                display: inline-block;
                position: relative;
                border: 2px solid black;
            }
            a::after {
                content: "";
                display: block;
                width: 0px;
                /* 使元素始终做水平居中,后续无论 width 怎么变化,都会自动居中 */
                left: 50%;
                transform: translateX(-50%);
                height: 1px;
                position: absolute;
                background-color: skyblue;
                transition: all 0.3s;
            }
            a:hover::after {
                width: 100%;
            }
        </style>
        <div class="box">
            <a href="">点我试试</a>
        </div>
    </body>
</html>
